package com.logicwin.aibala;


import com.logicwin.aibala.action.LoadStartUpAction;
import com.logicwin.aibala.action.LoadStartUpListener;
import com.logicwin.aibala.services.file.FileConnection;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.util.Log;
import android.view.Window;
import android.widget.ProgressBar;

public class LoadingActivity extends Activity{
	
	private ProgressBar loadingBar = null;
	public static LoadingActivity mContext;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        FileConnection.init(this.getApplicationContext().getFilesDir()
				.getAbsolutePath());
        mContext = this;
        setContentView(R.layout.loading);
        loadingBar = (ProgressBar)this.findViewById(R.id.loading_progressBar);
        loadingBar.setVisibility(ProgressBar.VISIBLE);
        
        start();
    }

	public void start() {
		// TODO Auto-generated method stub
		try {
			new LoadStartUpAction().startLoad(new LoadStartUpListener(){
				@Override
				public void loadProgress(int step){
					Log.i("loadingActivtiy", "loadProgress step="+step);
					loadingBar.incrementProgressBy(step);
					loadingBar.incrementSecondaryProgressBy(step);
				}

				@Override
				public void loadDone() {
					Log.i("loadingActivtiy", "loadDone");
					Intent intent = new Intent(LoadingActivity.mContext, Main.class);
					LoadingActivity.mContext.startActivity(intent);
					finish();
				}
				
			});
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
